<?php
namespace Home\Model;
use Think\Model;
use Common\Common\Classes\Message;

class StudentResultService extends Model{
    private $sr_sql;
    public function __construct(){
        $this->sr_sql = D("StudentResult");
    }
    //---------------------------------获得某个学生某个测试的测试成绩----------------------------------------------
    public function getStuQuizResult(){
        $field = array("qus_id","stu_score");
        $result = $this->sr_sql->where($_POST)->field($field)->order("qus_id desc")->find();
        if($result == ""){
            $result["qus_id"] = $_POST["qus_id"];
            $result["stu_score"] = "未交";
        }
        return $result;
    }
    //---------------------------------获得某张试卷的某个分数阶段的人数----------------------------------------------
    public function getSomeScoreNum(){      //post 试卷id和范围
        return $this->sr_sql->where($_POST)->count();
    }
    //---------------------------------获得某张试卷的合格人数(>=总分60%)----------------------------------------------
    public function getPassNum(){           //post 试卷id和合格分数
        return $this->sr_sql->where($_POST)->count();
    }
    //---------------------------------获得某张试卷的交卷人数----------------------------------------------
    public function getSubmitNum(){     //试卷id
        return $this->sr_sql->where($_POST)->count();
    }
    //---------------------------------获得某张试卷的最高分----------------------------------------------
    public function getMaxScore(){  //试卷id
        return $this->sr_sql->where($_POST)->max("stu_score");
    }
    //---------------------------------获得某张试卷的最低分----------------------------------------------
    public function getMinScore(){  //试卷id
        return $this->sr_sql->where($_POST)->min("stu_score");
    }
    //---------------------------------获得某张试卷的最低分(保留2位小数处理)----------------------------------------------
    public function getAvgScore(){      //试卷id
        return round($this->sr_sql->where($_POST)->avg("stu_score"),2);
    }
    //---------------------------------获取当前时间----------------------------------------------
    public function getTime(){
        return date("Y-m-d H:m:i",time());
    }
    public function __destruct(){}
}